<template>
  <el-row class="bar">
    <el-row class="topTab">
      <el-col :span="12" :class="currentTab === 0 ? 'focusTab':''">
        <div @click="currentTab = 0">组件</div>
      </el-col>
      <el-col :span="12" :class="currentTab === 1 ? 'focusTab':''">
        <div @click="currentTab = 1">图层</div>
      </el-col>
    </el-row>
    <!-- 占位符的作用 -->
    <div style="height: 30px;"></div>
    <div v-show="currentTab === 0" class="tools-container" v-for="group in options" :key="group.name" >
      <div class="tools-container-header"  @click="group.opened = !group.opened">
        <div style="display: inline-block;text-indent: 1em;width: 170px;">{{group.name}}</div>
        <div style="display: inline-block;">
          <i :class="group.opened ? 'el-icon-arrow-down':'el-icon-arrow-right'"></i>
        </div>
      </div>
      <el-row :gutter="2" v-show="group.opened" class="tools-container-content">
        <div class="tools-content-item-wrapper" v-for="(item, index) in group.children" :key="item.name + index">  
            <div class="tools-content-item" draggable="true" :config="JSON.stringify(item)" @dragstart="dragStart">
              <div style="line-height: 40px;">
                <embed v-if="item.icon" style="width: 20px;" :src="require('@/assets/icon/'+item.icon+'.svg')" type="image/svg+xml" />
                <i v-else style="font-size: 20px;" class="el-icon-question"></i>
              </div>
              <div style="font-size: 13px">{{ item.name }}</div>
            </div>
        </div>
      </el-row>
    </div>
    <div v-show="currentTab === 1">
      <div v-show="selectedComponents.length === 0" style="text-align: center;line-height: 50px;">
        无图层
      </div>
      <el-row v-for="(item,index) in selectedComponents" :key="item.keyId" class="selectedItem" 
              :style="{background: currentCptIndex === index ? '#23252b':'#1a1b1f'}">
        <el-col :span="4" style="text-align: center"><i :class="item.icon"/></el-col>
        <el-col :span="15" @click.native="showConfigBar($event,item,index)">{{item.cptTitle}}</el-col>
        <el-col :span="5" style="text-align: center">
          <i class="el-icon-copy-document" @click="copyCpt(item)"/>
          <i style="margin-left: 4px;" class="el-icon-delete" @click="delCpt(item,index)"/>
        </el-col>
      </el-row>
    </div>
  </el-row>
</template>

<script>
import options from '@/components/options'

export default {
  name: "componentBar",
  data() {
    return {
      options,
      cptGroupKeys:[],
      currentTab:0//0组件，1图层
    }
  },
  props:{
    selectedComponents:Array,
    currentCptIndex:Number
  },
  methods: {
    dragStart(e) {
      let copyDom = e.currentTarget.cloneNode(true);
      this.$emit('dragStart', copyDom);
    },
    showConfigBar(e,item,index){
      this.$emit('showConfigBar', e, item, index);
    },
    copyCpt(item){
      this.$emit('copyCpt', item);
    },
    delCpt(item,index){
      this.$emit('delCpt', item, index);
    }
  },
}
</script>

<style scoped>
.bar{
  position:relative;
  width:100%;
  height:100%;
  background:#0f1112;
  color: #fff;
  overflow-x:hidden;
  overflow-y: auto;
}
.bar::-webkit-scrollbar {
    width:4px;
    height:1px;
}
.bar::-webkit-scrollbar-thumb {
    border-radius: 6px;
    -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    background: rgba(194, 193, 193, 0.4);
}

.bar::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    border-radius: 6px;
    background:rgba(138, 139, 182, 0.3);
}
.el-collapse-item__*{background: #353f50}
.topTab{
  width:200px;
  height:30px;
  line-height:30px;
  text-align: center;
  cursor: pointer;
  position:fixed;
  z-index: 7;
  background:#383b41;
  box-shadow: 0 1px 3px #2b3340;
  font-size:1rem;
}
.topTab > div {
  border:1px solid #0e0f10;
  margin-left:-1px;
}
.topTab > div:first-child {
  margin-left:0;
}
.topTab > div.focusTab {
  background: #59616d
}
/* 组件库样式 */
.tools-container {}
.tools-container-header {
  height:30px;
  line-height:30px;
  cursor: pointer;
  box-shadow: 0 1px 2px #2B3340;
  background:#24272e;
}
.tools-container-content {
  background:#0f1112;
  display:flex;
  flex-wrap:wrap;
  padding-left:2px;
  padding-top:2px;
}
.tools-content-item-wrapper {
  width:50%;
  padding:0 2px 2px 0;
  box-sizing: border-box;
}
.tools-content-item {
  height:70px;
  text-align:center;
  background-color:#1a1b1f;
}
.selectedItem{
  font-size:1rem;
  padding-left:1rem;
  line-height: 45px;
  cursor: pointer;
  margin-bottom:1px;
}
</style>
